home *** CD-ROM | disk | FTP | other *** search
- Path: engnews1.Eng.Sun.COM!usenet
- From: johnb@pivotal-dm.ccmail.compuserve.com (John Bain)
- Newsgroups: comp.std.c++
- Subject: Re: Referencing pointers after delete
- Date: 23 Mar 1996 17:09:03 GMT
- Organization: Pivotal Technologies Ltd.
- Approved: clamage@eng.sun.com (comp.std.c++)
- Message-ID: <315274d1.8486150@dub-news-svc-3.compuserve.com>
- References: <4is05t$ceo@engnews1.Eng.Sun.COM>
- NNTP-Posting-Host: taumet.eng.sun.com
- X-Nntp-Posting-Host: hd62-202.compuserve.com
- X-Newsreader: Forte Agent .99d/32.182
- Content-Length: 1280
-
- "joe (j.) halpin" <jhalpin@bnr.ca> wrote:
-
- >In 3.7.3.2.4 the January working paper says:
- >
- >4 A deallocation function can free the storage referenced by the pointer
- > given as its argument and renders the pointer invalid. The storage
- > can be made available for further allocation. An invalid pointer con-
- > tains an unusable value: it cannot even be used in an expression.
-
- I interpret this as meaning the _value_ of the pointer cannot be used in
- an expression.
-
- >
- >This sounds as though, in the following:
- >
- >char *pc = new char[128];
- >delete pc;
- ^^^^
- delete[] pc;
-
- >pc = 0;
- >
- >it makes the final assignment (an expression) invalid.
-
- The value of the pointer is not used in the expression, so it's OK.
-
- >In fact, it sounds like it also rules out things like 'if(pc == 0)
- >...' after the above fragment.
-
- After the final assignment, the pointer's value is no longer invalid, so
- it can be used (though obviously not dereferenced while NULL).
-
- By my interpretation, (pc == 0) would, however, be invalid after the
- delete but before the assignment of 0.
-
- Cheers,
-
- John
- -----------------------------------------------------------------
- John Bain
- johnb@pivotal-dm.ccmail.compuserve.com
- -----------------------------------------------------------------
-
-
-
- [ comp.std.c++ is moderated. To submit articles: try just posting with ]
- [ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
- [ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
- [ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
- [ Comments? mailto:std-c++-request@ncar.ucar.edu ]
-